package cn.com.test.common.proxy;

import cn.com.test.common.proxy.service.UserService;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class InvocationHandlerImpl implements InvocationHandler {

	private UserService userService;

	public InvocationHandlerImpl(UserService userService) {
		this.userService = userService;
	}

	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		before();
		method.invoke(userService, args);
		after();
		return "success";
	}

	private void before() {
		System.out.println("事务开始---");
	}

	private void after() {
		System.out.println("事务结束---");
	}
}
